package comp353Games;

//imported packages
import javax.swing.*;
import java.awt.*;

/**
 * SnortDisplay is a container for the graphical representation of Snort.
 *
 * @author Andre Harvey, Deanna Fink, Tyler Radley
 * @version 3/25/12
 */
public class SnortColDisplay extends JPanel {

    //instance variables
    
    // The Snort game this will display.
    private SnortCol game;

    /**
     * Class constructor.
     *
     * @param game The Snort instance this will display.
     */
    public SnortColDisplay(GameModel game) {
        this.game = (Snort) game;
        this.setOpaque(true);
    }

    @Override
    protected void paintComponent(Graphics graphics) {

        for (int i = 0; i < game.getRows().length; i++) {

            for (int j = 0; j < ((game.getRows())[i]).length; j++) {
                graphics.setColor(Color.white);
                graphics.drawOval((j * 30 + 40), (i * 35 + 40), 20, 20);
                if (j < (game.getRows()[i]).length - 1) {
                    graphics.drawLine((j * 30 + 60), (i * 35 + 50), (j * 30 + 80), (i * 35 + 50));
                }
                if (game.getRows()[i][j] == 2) {
                    graphics.setColor(Color.red);
                    if ((j < game.getRows()[i].length-1 && game.getRows()[i][j+1] == 2)){
                       graphics.drawLine((j * 30 + 60), (i * 35 + 50), (j * 30 + 80), (i * 35 + 50));
                    }
                }
                if (game.getRows()[i][j] == 1) {
                    graphics.setColor(Color.blue);
                    if ((j < game.getRows()[i].length-1 && game.getRows()[i][j+1] == 1)){
                       graphics.drawLine((j * 30 + 60), (i * 35 + 50), (j * 30 + 80), (i * 35 + 50));
                    }
                }
                graphics.fillOval((j * 30 + 39), (i * 35 + 39), 22, 22);
               

            }
        }

    }

    @Override
    public Dimension getPreferredSize() {
        int width = 610;
        int height = 514;
        return new Dimension(width, height);
    }

    /**
     * A dimension object of the size needed to display the status messages in
     * the display
     *
     * @return The dimension object of the size needed to display the status
     * messages in the display
     */
    public Dimension getStatusBarPreferredSize() {
        int width = 40 + 140 * this.game.getRows().length;
        int height = 50;
        return new Dimension(width, height);

    }
}